import django_filters
from django.db.models import Q
from django_filters import FilterSet

from order.models import Order


class OrderFilter(FilterSet):
    totalmax = django_filters.NumberFilter(field_name='total', lookup_expr='gte')
    totalmin = django_filters.NumberFilter(field_name='total', lookup_expr='lte')

    movie_id = django_filters.NumberFilter(field_name='movie')

    def movie_id_filter(self,queryset, name, value):
        result = queryset.filter(Q(movie_id=value) | Q(user__order__movie_id=value))
        return result

    class Meta:
        model = Order
        fields = ['total']